https://www.zabbix.com/documentation/3.4/zh/manual/config/items/userparameters
設定自定義腳本
vi /etc/zabbix/zabbix_agentd.conf
### Option: Include
Include=/etc/zabbix/zabbix_agentd.d/*.conf
####### USER-DEFINED MONITORED PARAMETERS #######
UnsafeUserParameters=1
裝zabbix-get來測試,呼叫userparameter_mysql.conf查看mysql版本
yum install zabbix-get
zabbix_get -s 127.0.0.1 -p 10050 -k "mysql.version"
查看userparameter_mysql.conf內設定,可以看出下mysql.version時,執行mysql -V
UserParameter=mysql.version,mysql -V
範例:
收集apache的連線數
https://httpd.apache.org/docs/2.4/mod/mod_status.html
vi /etc/httpd/conf/httpd.conf
加入以下指令,有資安疑慮則將all改成內部IP
<Location /server-status>
SetHandler server-
Order allow,deny
Allow from all
</Location>
利用curl讀網頁,並用grep篩選,awk取出要的資訊
curl -s "http://172.16.1.1/server-status?auto" | grep 'BusyWorkers' | awk '{print $2}'
寫成腳本 vi /usr/lib/zabbix/externalscripts/apache_status.sh
#!/bin/bash
ip=$1
apachestatus=http://${ip}/server-status?auto
curl -s "$apachestatus" | grep 'BusyWorkers' | awk '{print $2}'
增加zabbix自定義參數 vi /etc/zabbix/zabbix_agentd.d/userparameter_apache.conf
UserParameter=apache.status[*],/usr/lib/zabbix/externalscripts/apache_status.sh $1
zabbix agent重啟後,用get測試看看
zabbix_get -s 127.0.0.1 -p 10050 -k "apache.status[172.16.1.1]"
如果get的到資料後,回到web新增items即可